<?php foreach ($edit_data as $key): ?>
<form class="form-horizontal" id="ap_editform">
<div class="ibox float-e-margins">
    <div class="ibox-title"  style="border: none;"><h5 style="color: #00afef"><i>Edit Accounting Periods</i></h5>
        <div class="ibox-tools">    
            <button class="btn btn-primary btn-sm save-btn-tab" type="">Save</button>
            <a id="cancel_edit" class="btn-outline btn btn-info btn-sm cancel-btn-tab">Cancel</a>
        </div>
    </div>
    <div class="ibox-content">
            <div class="form-group">
                <label class="col-lg-4 control-label">Business Unit</label>
                <div class="col-lg-3">
                    <input readonly name="business_unit_e" value="<?php echo $key->bu_name; ?>" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-4 control-label">Fiscal Year</label>
                <div class="col-lg-4">
                    <input type="number" value="<?php echo $key->fiscal_year; ?>" name="fiscal_year_e" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-4 control-label">Name</label>
                <div class="col-lg-5">
                    <input  name="period_name_e" value="<?php echo $key->period_name; ?>" type="text" class="form-control">
                </div>
            </div>
            <input  name="period_id_e" value="<?php echo $key->period_id; ?>" type="hidden">
            <!-- <div class="form-group" id="data_5">
                <label class="col-lg-4 control-label">Date Range</label>
                <div class="col-lg-5">
                    <div id="datepicker" class="input-daterange input-group">
                        <input type="text" value="10/05/2015" name="start" class="input-sm form-control">
                        <span class="input-group-addon">to</span>
                        <input type="text" value="10/20/2015" name="end" class="input-sm form-control">
                    </div>
                </div>
            </div> -->
            <div class="form-group" id="start-date">
                <label class="col-lg-4 control-label">Start Date</label>
                <div class="col-lg-3">
                   <div class="input-group">
                        <span class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </span>
                        <input value="<?php echo $key->start_date; ?>" type="date" value="" name="opened_date_e" class="form-control">
                    </div>
                </div>
            </div>
            <div class="form-group" id="end-date">
                <label class="col-lg-4 control-label">End Date</label>
                <div class="col-lg-3">
                   <div class="input-group">
                        <span class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </span>
                        <input value="<?php echo $key->end_date; ?>" name="closed_date_e" type="date" class="form-control">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-4 control-label">Status</label>
                <div class="col-lg-3">
                    <input value="<?php echo $key->status_desc; ?>" type="text" name="status_e" class="form-control" readonly>
                </div>
            </div>
        </form>
    </div>
</div> <!-- End of iBox -->
<?php endforeach; ?>
<script type="text/javascript">
    $(document).ready(function() {
        $('#ap_editform').data('serialize',$('#ap_editform').serialize());
        function alert_cancel(){
                    if($('#ap_editform').serialize()!=$('#ap_editform').data('serialize')){
                        swal({
                              title: "Are you sure?",
                              text: "Your work will not be save",
                              type: "warning",
                              showCancelButton: true,
                              confirmButtonColor: "#DD6B55",
                              confirmButtonText: "Leave",
                              cancelButtonText: "Stay",
                              closeOnConfirm: true,
                              closeOnCancel: true },
                          function (isConfirm) {
                              if (isConfirm) {
                                  close_edit(); active_search();
                                  notifymsg("hide","hide");
                              } else {
                                  swal("Cancelled");
                              }
                          });
                        }else{
                        close_edit(); active_search();
                        notifymsg("hide","hide");
                    }
                }
                $('#cancel_edit').click(function(){
                    alert_cancel();
                });
              $('#editX').click(function(){
                    alert_cancel();
              });
        $("#ap_editform").validate({
             rules: {
                 fiscal_year_e: {
                    required : true,
                    number: true
                 },
                 opened_date_e: {
                    required : true
                 },
                 closed_date_e: {
                    required : true
                 },
                 status_e: {
                    required : true
                 },
                 period_name_e: {
                    required : true
                 }
             },
             submitHandler: function(form){
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url($this->session->userdata('forajax').'/editgp'); ?>",
                    data: $('#ap_editform').serialize(),
                    dataType: 'json',
                    success: function(e){
                        if(e.err == 1){
                            notifymsg('danger','<b>Error</b>: ' + e.msg);
                        }else{
                            notifymsg('success','<b>Success</b>: Data Saved');
                            $('#tab-list-2 a:first').tab('show');
                            $('#edit').remove();
                            $('#edit-link').remove();
                            $('#count_edit').val('0');
                            //$('#search-ap').trigger('click');
                        }
                    }       
                });
             }
        });

    });
</script>